package com.stable.actor.messages;

import java.io.Serializable;

/**
 * 通用的消息协议
 */
public class MessageProtocol {

    // 注册消息
    public static class Register implements Serializable {
        private static final long serialVersionUID = 1L;
        public final String clientId;
        public final String clientType;

        public Register(String clientId, String clientType) {
            this.clientId = clientId;
            this.clientType = clientType;
        }

        @Override
        public String toString() {
            return "Register{clientId='" + clientId + "', clientType='" + clientType + "'}";
        }
    }

    // 注册响应
    public static class RegisterAck implements Serializable {
        private static final long serialVersionUID = 1L;
        public final String clientId;
        public final String status;
        public final String message;

        public RegisterAck(String clientId, String status, String message) {
            this.clientId = clientId;
            this.status = status;
            this.message = message;
        }
    }

    // 工作请求
    public static class WorkRequest implements Serializable {
        private static final long serialVersionUID = 1L;
        public final String clientId;
        public final int requestId;
        public final String task;

        public WorkRequest(String clientId, int requestId, String task) {
            this.clientId = clientId;
            this.requestId = requestId;
            this.task = task;
        }
    }

    // 工作响应
    public static class WorkResponse implements Serializable {
        private static final long serialVersionUID = 1L;
        public final String clientId;
        public final int requestId;
        public final String result;
        public final long processingTime;

        public WorkResponse(String clientId, int requestId, String result, long processingTime) {
            this.clientId = clientId;
            this.requestId = requestId;
            this.result = result;
            this.processingTime = processingTime;
        }
    }

    // 心跳消息
    public static class Heartbeat implements Serializable {
        private static final long serialVersionUID = 1L;
        public final String from;
        public final long timestamp;

        public Heartbeat(String from) {
            this.from = from;
            this.timestamp = System.currentTimeMillis();
        }
    }

    // 心跳响应
    public static class HeartbeatAck implements Serializable {
        private static final long serialVersionUID = 1L;
        public final String from;
        public final long timestamp;

        public HeartbeatAck(String from) {
            this.from = from;
            this.timestamp = System.currentTimeMillis();
        }
    }
}
